using System;

namespace Deepcode.Flux.Core.Collections
{
	/// <summary>
	/// Provides storage of a BaseDictionary object in session space. 
	/// This is generally used to hold multipage entry information for example in
	/// setup wizards and such like.
	/// </summary>
	public class SessionDictionary
	{
		/// <summary>
		/// Retrieve the current BaseDictionary object from the session,
		/// or, if it doesn't yet exist, create it. Always stores the dictionary
		/// in the session key SetupDic
		/// </summary>
		public static BaseDictionary Config
		{
			get
			{
				System.Web.SessionState.HttpSessionState Session = System.Web.HttpContext.Current.Session;
				object sessObj = Session["SetupDic"];
				if( sessObj == null )
				{
					BaseDictionary dic = new BaseDictionary();
					Session["SetupDic"] = dic;
					return (BaseDictionary) Session["SetupDic"];
				}
				return (BaseDictionary) sessObj;
			}
		}

		/// <summary>
		/// Returns the items in this session dictionary as an array of DictionaryItems
		/// </summary>
		/// <returns></returns>
		public static Deepcode.Flux.Core.Collections.BaseDictionary.DictionaryItem [] AsArray()
		{
			return Config.ToArray();
		}
	}
}
